import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/network/Api.dart';
import 'package:huajianshe_app/network/response/BaseResp.dart';
import 'package:huajianshe_app/pages/mine/ImportFriendsDialog.dart';
import 'package:huajianshe_app/widget/BgImageLayout.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';
import 'package:huajianshe_app/widget/appbar/CAppBar.dart';
import 'package:oktoast/oktoast.dart';

import 'CircleListPage.dart';


//管理圈子
class CircleManagementPage extends StatefulWidget {

  final int? circleId;
  final String? name;
  final int? viewNum;
  final double? score;
  final String? importUrl;

  const CircleManagementPage(this.circleId, this.name, this.viewNum, this.score, this.importUrl, {Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _CircleManagementPageState();
  }
}

class _CircleManagementPageState extends BaseState<CircleManagementPage> {

  @override
  void initState() {
    super.initState();
  }

  @override
  void onReqSuccess<T>(T t, int code, String msg, String path) {
    if (t is BaseResp) {
      showToast(t.msg ?? '');
    }
  }

  @override
  Widget build(BuildContext context) {
    return BgImageLayout(imageHeight: 162, imageUrl: 'bg_circle_management', bgColor: C.grayF6, children: [
      Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        RoundedCornerWidget(margin: EdgeInsets.only(top: 148), backgroundColor: C.grayF6, radius: 13, width: double.infinity, height: 37,
            child: Padding(padding: EdgeInsets.only(left: 15, top: 15), child: Text('基本信息', style: TS(13, C.gray666)))
        ),
        Padding(padding: EdgeInsets.symmetric(horizontal: 15),
            child: RoundedCornerWidget(width: double.infinity, height: 70, radius: 13, borderWidth: 0,
                gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter,
                    colors: [Color(0xffFE2E2E), Color(0xffF78C58)]),
                child: Row(children: [
                  Expanded(
                    flex: 1,
                    child: Center(child: Text('圈子数据', style: TS(13, Colors.white))),
                  ),
                  VD(20.0, color: Color.fromRGBO(255, 255, 255, 0.3)),
                  Expanded(
                    flex: 1,
                    child: Column(mainAxisSize: MainAxisSize.min, children: [
                        Text('本日浏览数', style: TS(13, Colors.white)),
                        H(8),
                        Text('${widget.viewNum ?? 0}', style: TS(17, Colors.white))
                      ]),
                  ),
                  VD(20.0, color: Color.fromRGBO(255, 255, 255, 0.3)),
                  Expanded(
                    flex: 1,
                    child: Column(mainAxisSize: MainAxisSize.min, children: [
                      Text('评价', style: TS(13, Colors.white)),
                      H(8),
                      Text('${widget.score ?? 0}', style: TS(17, Colors.white))
                    ]),
                  ),
                ])
            ),
        ),
        H(16),
        Padding(padding: EdgeInsets.only(left: 15), child: Text('基本设置', style: TS(13, C.gray666))),
        H(11),
        Padding(padding: EdgeInsets.symmetric(horizontal: 15),
            child: RoundedCornerWidget(width: double.infinity, height: 77, radius: 13, borderWidth: 0, backgroundColor: Colors.white,
                child: Row(children: [
                    Expanded(flex: 1, child: Center(
                        child: SmartButton(width: 60, height: 60, text: '成员管理', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                          borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_manage'), drawablePadding: 12, onPressed: memberManagement,)
                    )),
                    Expanded(flex: 1,child: SmartButton(width: 60, height: 60, text: '圈子设置', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                      borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_setting'), drawablePadding: 12, onPressed: circleSetting,)
                    ),
                    Expanded(flex: 1, child: Center(
                        child: SmartButton(width: 60, height: 60, text: '推广海报', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                        borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_poster'), drawablePadding: 12, onPressed: post,)
                    ))
                ]),
            )
        ),
        H(16),
        Padding(padding: EdgeInsets.only(left: 15), child: Text('高级设置', style: TS(13, C.gray666))),
        H(11),
        Padding(padding: EdgeInsets.symmetric(horizontal: 15),
            child: RoundedCornerWidget(width: double.infinity, height: 170, radius: 13, borderWidth: 0, backgroundColor: Colors.white,
                child: Column(children: [
                  H(18),
                  Row(children: [
                    Expanded(flex: 1, child: Center(
                        child: SmartButton(width: 60, height: 60, text: '导入名单', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                            borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_import'), drawablePadding: 12, onPressed: import,)
                    )),
                    Expanded(flex: 1,child: SmartButton(width: 60, height: 60, text: '导出名单', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                        borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_export'), drawablePadding: 12, onPressed: export,)
                    ),
                    Expanded(flex: 1, child: Center(
                        child: SmartButton(width: 60, height: 60, text: '圈子通知', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                            borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_notification'), drawablePadding: 12)
                    ))
                  ]),
                  H(18),
                  Row(children: [
                    Expanded(flex: 1, child: Center(
                        child: SmartButton(width: 100, height: 60, text: '管理员设置', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                            borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_captain'), drawablePadding: 12)
                    )),
                    Expanded(flex: 1,child: SmartButton(width: 100, height: 60, text: '圈子功能管理', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                        borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_function'), drawablePadding: 12)
                    ),
                    Expanded(flex: 1, child: Center(
                        child: SmartButton(width: 100, height: 60, text: '收支记录', textColor: C.gray333, fontSize: 13, backgroundColor: Colors.transparent,
                            borderColor: Colors.transparent, drawableTop: LoadImage('ic_management_record'), drawablePadding: 12)
                    ))
                  ]),
                ])
            )
        )
      ]),
      CAppBar(title: widget.name ?? '', backImgUrl: 'ic_white_arrow', titleColor: Colors.white)
    ]);

  }
  
  memberManagement() {
    AppNavigator.push(context, RouteName.MEMBER_MANAGEMENT, arguments: {'circleId': widget.circleId});
  }

  circleSetting() {
    AppNavigator.push(context, RouteName.CIRCLE_EDIT, arguments: {'circleId': widget.circleId});
  }

  post() {

  }

  import() {
    AppNavigator.push(context, RouteName.CIRCLE_ADD_MEMBER, arguments: {'circleId': widget.circleId, 'importUrl': widget.importUrl});
  }

  export() {
    sendReq(Api.exportFriends(), BaseResp(), data: {'circle_id': widget.circleId});
  }
}